﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WCLOnlineExam.Models
{
    //[EntityAuthentication(AllowAnonymous = false, ViewRolesRequired = new string[] { "Admin" })]
    [ParentAttribute(typeof(UserGroup), "Group")]
    [DisplayColumn("UserName", "UserName")]
    public class User : UserBase
    {

        [Display(Name="用户名")]
        [Required(ErrorMessage="姓名不能为空")]
        public virtual string UserName { get; set; }

        [CustomDataType(CustomDataType.Password)]
        [Display(Name = "密码", Order = 10)]
        [Hide(IsHiddenOnEdit = false, IsHiddenOnDetail = true)]
        [MaxLength(20)]
        [Required]
        public override byte[] Password { get; set; }

        [CustomDataType(CustomDataType.Sex)]
        [Display(Name="性别")]
        [Required]
        public virtual bool Gender { get; set; }

        [Display(Name = "所属组", Order = 70)]
        [Required]
        public virtual UserGroup Group { get; set; }
        
        [Display(Name = "电子邮件", Order = 70)]
        [CustomDataType(CustomDataType.EmailAddress)]
        public virtual string Email { get; set; }

        [Display(Name = "联系电话", Order = 60)]
        [CustomDataType(CustomDataType.PhoneNumber)]
        public virtual string Phone { get; set; }

        [Hide(IsHiddenOnEdit = true)]
        [Display(Name = "是否删除", Order = 70)]
        public virtual Status isDeleted { get; set; }

        public override bool IsInRole(string role)
        {
            return Group.Power.ToString() == role;
        }
    }
    public enum Status
    {
        DisDeleted = 0,
        IsDeleted = 1
    }
}